{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e2f45563-1227-4976-9101-15ec1ce60fda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "081323e331184489b442596a2afa292d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=10, description='x', max=30, min=-10), Output()), _dom_classes=('widget-…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_2x(x)>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "\n",
    "# 数值参数: 数值滚动条\n",
    "def fun_2x(x):\n",
    "    return 2*x\n",
    "\n",
    "interact(fun_2x, x=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "046b63a5-bc5a-44ff-8e9d-dd68302e6d22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "61a137c7141a4473a54c53420238e2d6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_bool(x)>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 布尔参数: 复选框\n",
    "def fun_bool(x):\n",
    "    return x\n",
    "\n",
    "interact(fun_bool, x=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e1d1e1a2-7899-4aa3-aa23-17a72a18722d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0addeb7b6e724c3983b07ba25db83f38",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Text(value='', description='x'), Output()), _dom_classes=('widget-interact',))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_text_box(x)>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 文本参数: 文本输入框\n",
    "def fun_textbox(x):\n",
    "    return x\n",
    "\n",
    "interact(fun_text_box, x='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "095ea1a3-9c0d-4a95-abf9-e6c65c794ba1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "77f60bcaf5624e219dd97bdabef696b7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='x', options=('Tom', 'Jack', 'Lilisi', 'Lucy'), value='Tom'), Outpu…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_list(x)>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表参数: 下拉框\n",
    "def fun_list(x):\n",
    "    return x\n",
    "\n",
    "interact(fun_list, x=[\"Tom\",\"Jack\",\"Lilisi\",\"Lucy\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "eb13d760-141f-4bbb-bf4a-04fd8bbe0ac7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ce36ef5bc14f47239ce33d861e439778",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='x', options={'Tom': 18, 'Jerry': 20, 'Lucy': 22}, value=18), Outpu…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_list(x)>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表参数: 下拉框\n",
    "def fun_list(x):\n",
    "    return x\n",
    "\n",
    "data = {\n",
    "    \"Tom\": 18,\n",
    "    \"Jerry\": 20,\n",
    "    \"Lucy\": 22,\n",
    "}\n",
    "interact(fun_list, x=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bc6f96f1-c7eb-4bab-8f01-221f3dd8170a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6fe5e6778c4241be8ed69f2205e1ef68",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=10, description='x', step=5), Output()), _dom_classes=('widget-interact'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.fun_int_slider(x)>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fun_int_slider(x):\n",
    "    return x\n",
    "\n",
    "int_slider = widgets.IntSlider(min=0, max=100, step=5, value=10)\n",
    "interact(fun_int_slider, x=int_slider)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "193e3157-288a-41b1-bd14-cf8e23999437",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
